package com.swyc.osschat.Test.LambdaTest.Controller;

import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.DoubleBinaryOperator;
import java.util.function.Function;

import com.google.common.collect.Lists;
import com.swyc.osschat.Test.LambdaTest.Bean.Student;

/**
 * @author zhaol@yunrong.cn
 * @version V2.1
 * @since 2.1.0 2019/8/13 9:34
 * BinaryOperator<T>
 * 提供两个参数，并且返回结果与输入参数类型一致的结果
 * DoubleBinaryOperator
 * 提供两个double参数并且返回double结果
 * DoubleUnaryOperator
 * 提供单个double参数并且返回double结果
 * IntBinaryOperator
 * 提供两个int参数并且返回int结果
 * IntUnaryOperator
 * 提供单个int参数并且返回int结果
 * LongBinaryOperator
 * 提供两个long参数并且返回long结果
 * LongUnaryOperator
 * 提供单个long参数并且返回long结果
 */
public class BinaryOperatorTest2 {
    private static final List<Student> students = Student.generateData();

    public static void main(String[] args) {
        List<Student> studentList = Lists.newArrayList();
        BinaryOperator<Student> binaryOperator = (x,y)->{
            studentList.add(x);
            studentList.add(y);
            return studentList.get(0);
        };
        Student student1 = binaryOperator.apply(students.get(2), students.get(5));
        Function<Student, Student> function = a -> Student.modifyStudentAge(a,10000);
        Student student2 = binaryOperator.andThen(function).apply(students.get(2), students.get(5));
        System.out.println(Student.beanToString(student1)+Student.beanToString(student2));
        /** DoubleBinaryOperator提供两个double参数并且返回double结果 */
        DoubleBinaryOperator doubleBinaryOperator = (doub1, doub2) -> doub1+ doub2;
        System.out.println(doubleBinaryOperator.applyAsDouble(889.67,673.27));
        /** 比较大小 */
        BinaryOperator<Integer> bi1 = BinaryOperator.maxBy(Comparator.naturalOrder());
        BinaryOperator<Integer> bi2 = BinaryOperator.minBy(Comparator.naturalOrder());
        System.out.println(bi1.apply(2, 3)+"<->"+ bi2.apply(2, 3));
    }
}
